long lastbuttonstate =  LOW;//定义上次开关状态
long lastbuttontime = 0;//定义一个时间
long debouncetime = 50;//定义防抖动时间
long buttonstate ;//定义开关的现在的状态
int inputPin = 8;

void setup()
{
  pinMode(inputPin,INPUT);
  Serial.begin(9600);
}

void loop() {
  int reading = digitalRead(inputPin);
  Serial.println(reading);
  if(reading != buttonstate)
  {
    long lastbuttontime = millis();
  }
  if( (millis()-lastbuttontime) > debouncetime)
    {
       if(reading != buttonstate)
      {
         reading = buttonstate;
         delay(500);
      }
    }
}
